﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="DoAnPhatTrienPhanMem.Controllers" %>
<%@ Import Namespace="DoAnPhatTrienPhanMem.Models" %>
<%@ Import Namespace="DoAnPhatTrienPhanMem.Constants" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Phân công</title>
    <script src="/Scripts/CommonFunction.js" type="text/javascript"></script>
    <script src="/Scripts/Constant.js" type="text/javascript"></script>
    <link href="/Content/MainStyle.css" rel="stylesheet" type="text/css" />
    <script runat="server">
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Ext.Net.MenuItem node;
                node = new Ext.Net.MenuItem { Text = "Lưu" };
                node.Listeners.Click.Handler = "CommonFunction.submit();";
                MainMenu.Menu.Add(node);
                var IDphong = ViewData["IDphong"].ToString();
                var IDban = ViewData["IDban"].ToString();
                var IDcanbo = ViewData["IDcanbo"].ToString();
                if (!String.IsNullOrEmpty(IDphong))
                {
                    ThuocBanVien.SelectedItem.Value = "VIEN";
                    var PhongCtrl = new PhongKhoaHocController();
                    var phong = PhongCtrl.GetPhongByID(IDphong);
                    cboVien.Hidden = false;
                    cboPhong.Hidden = false;
                    cboPhong.Disabled = false;
                    cboBan.Hidden = true;
                    cboVien.SelectedItem.Value = phong.MaVien.ToString();
                    cboPhong.SelectedItem.Value = phong.MaPhong.ToString();
                    MaPhongBan.Text = phong.MaPhong.ToString();
                }
                else if (!String.IsNullOrEmpty(IDban))
                {
                    ThuocBanVien.SelectedItem.Value = "BAN";
                    var BanCtrl = new BanHanhChinhController();
                    var ban = BanCtrl.GetBanByID(IDban);
                    cboVien.Hidden = true;
                    cboPhong.Hidden = true;
                    cboPhong.Disabled = true;
                    cboBan.Hidden = false;
                    cboBan.SelectedItem.Value = ban.MaBan.ToString();
                    MaPhongBan.Text = ban.MaBan.ToString();
                }
                else if (!String.IsNullOrEmpty(IDcanbo))
                {
                    var CanBoCtrl = new CanBoController();
                    var canbo = CanBoCtrl.GetCanBoByID(IDcanbo);
                    MaCB.SelectedItem.Value = canbo.MaCB.ToString();
                    NgaySinh.Text = canbo.NgaySinh.ToString("dd/MM/yyyy");
                    SoHieuCongChuc.Text = canbo.SoHieuCongChuc;
                    TenBanVien.Text = canbo.TenBanVien;
                    if (canbo.ViTri == "TRUONG")
                    {
                        ViTri1.Text = "Trưởng";
                    }
                    else if (canbo.ViTri == "PHO")
                    {
                        ViTri1.Text = "Phó";
                    }
                    else if (canbo.ViTri == "NHANVIEN")
                    {
                        ViTri1.Text = "Nhân viên";
                    }
                }

                var user = "";
                if (Session[Constants.SessionName.UserName] != null) user = Session[Constants.SessionName.UserName].ToString();
                if (!String.IsNullOrEmpty(user))
                {
                    frmLogin.Hidden = true;
                    btnLogin.Hidden = true;
                    UserID.Text = user;
                    //UserID.NavigateUrl = "#";
                    UserID.Hidden = false;
                    afterLogin.Hidden = false;
                    var AccountCtrl = new AccountController();
                    var MaCB = AccountCtrl.GetByUserName(user).MaCB;
                    if (MaCB != null)
                    {
                        var CanBoCtrl = new CanBoController();
                        var IDcb = CanBoCtrl.GetSoYeuCanBoByMaCB(MaCB.ToString()).ID;
                        UserID.Listeners.Click.Handler = "CommonFunction.loadPage('CanBo','Details',{ID: '" + IDcb + "'});";
                    }
                }
            }
        }
    </script>
    <script type="text/javascript">
        function selectCanBo(selectedItem) {
            var MaCanBo = selectedItem.value;
            var CanBo = window.storeCanBo.getById(MaCanBo);
            window.NgaySinh.setText(CanBo.data.NgaySinh);
            window.SoHieuCongChuc.setText(CanBo.data.SoHieuCongChuc);
            window.TenBanVien.setText(CanBo.data.TenBanVien);
            window.ViTri1.setText(CanBo.data.ViTri);
        }
        function convertViTri(value) {
            if (value == "TRUONG") return "Trưởng";
            else if (value == "PHO") return "Phó";
            else if (value == "NHANVIEN") return "Nhân viên";
            else return "";
        }
        function selectVien(selectedItem) {
            window.cboPhong.setDisabled(false);
            window.cboPhong.clear();
            var MaVien = selectedItem.value;
            window.storePhong.reload({ params: { MaVien: MaVien} });
        }
        function selectBanVien(selectedItem) {
            var val = selectedItem.value;
            if (val == "VIEN") {
                window.cboVien.setVisible(true);
                window.cboPhong.setVisible(true);
                window.cboBan.setVisible(false);
            } else {
                window.cboVien.setVisible(false);
                window.cboPhong.setVisible(false);
                window.cboBan.setVisible(true);
            }
        }
        function selectPhong(selectedItem) {
            var val = selectedItem.value;
            window.MaPhongBan.setValue(val);
        }
        function selectBan(selectedItem) {
            var val = selectedItem.value;
            window.MaPhongBan.setValue(val);
        }
    </script>
</head>
<body id="bd" class="fs3">
    <ext:ResourceManager runat="server" Locale="vi-VN" CleanResourceUrl="false" />
    <div id="ja-wrapper">
        <div id="ja-container" class="wrap clearfix">
            <div class="main">
                <div class="inner clearfix">
                    <div id="ja-mainbody">
                        <ext:FormPanel ID="frmMain" runat="server" Url="/CanBo/SavePhanCong">
                            <Items>
                                <ext:ColumnLayout ID="ColumnLayout1" runat="server">
                                    <Columns>
                                        <ext:LayoutColumn ColumnWidth="0.5">
                                            <ext:Panel ID="Panel1" runat="server" Layout="FormLayout" LabelWidth="120" Border="false"
                                                Height="500">
                                                <Items>
                                                    <ext:Label runat="server" Text="Chọn cán bộ" />
                                                    <ext:ComboBox runat="server" ID="MaCB" FieldLabel="Cán bộ" DisplayField="HoTen" ValueField="MaCB">
                                                        <Store>
                                                            <ext:Store ID="storeCanBo" runat="server" AutoLoad="true">
                                                                <Proxy>
                                                                    <ext:HttpProxy Url="/CanBo/GetCanBo" />
                                                                </Proxy>
                                                                <Reader>
                                                                    <ext:JsonReader Root="data" IDProperty="MaCB">
                                                                        <Fields>
                                                                            <ext:RecordField Name="ID" />
                                                                            <ext:RecordField Name="MaCB" />
                                                                            <ext:RecordField Name="HoTen" />
                                                                            <ext:RecordField Name="NgaySinh">
                                                                                <Convert Fn="CommonFunction.renderDate" />
                                                                            </ext:RecordField>
                                                                            <ext:RecordField Name="ThuocBanVien" />
                                                                            <ext:RecordField Name="MaPhongBan" />
                                                                            <ext:RecordField Name="ViTri">
                                                                                <Convert Fn="convertViTri" />
                                                                            </ext:RecordField>
                                                                            <ext:RecordField Name="TenBanVien" />
                                                                            <ext:RecordField Name="SoHieuCongChuc" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <Listeners>
                                                            <Select Fn="selectCanBo" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                    <ext:Hidden runat="server" ID="ID" />
                                                    <ext:Label runat="server" ID="NgaySinh" FieldLabel="Ngày sinh" />
                                                    <ext:Label runat="server" ID="SoHieuCongChuc" FieldLabel="Số hiệu công chức" />
                                                    <ext:Label runat="server" ID="TenBanVien" FieldLabel="Đơn vị hiện tại" />
                                                    <ext:Label runat="server" ID="ViTri1" FieldLabel="Vị trí" />
                                                </Items>
                                            </ext:Panel>
                                        </ext:LayoutColumn>
                                        <ext:LayoutColumn ColumnWidth="0.5">
                                            <ext:Panel ID="Panel2" runat="server" Layout="FormLayout" LabelWidth="120" Border="false">
                                                <Items>
                                                    <ext:Label runat="server" Text="Chọn đơn vị" />
                                                    <ext:ComboBox runat="server" ID="ThuocBanVien" FieldLabel="Ban/Viện">
                                                        <Items>
                                                            <ext:ListItem Text="Viện khoa học" Value="VIEN" />
                                                            <ext:ListItem Text="Ban hành chính" Value="BAN" />
                                                        </Items>
                                                        <Listeners>
                                                            <Select Fn="selectBanVien" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                    <ext:ComboBox runat="server" ID="cboVien" DisplayField="TenVien" ValueField="MaVien"
                                                        Hidden="true" FieldLabel="Viện">
                                                        <Store>
                                                            <ext:Store runat="server" ID="storeVien" AutoLoad="true">
                                                                <Proxy>
                                                                    <ext:HttpProxy Url="/VienKhoaHoc/GetAll" />
                                                                </Proxy>
                                                                <Reader>
                                                                    <ext:JsonReader Root="data">
                                                                        <Fields>
                                                                            <ext:RecordField Name="ID" />
                                                                            <ext:RecordField Name="MaVien" />
                                                                            <ext:RecordField Name="TenVien" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <Listeners>
                                                            <Select Fn="selectVien" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                    <ext:ComboBox runat="server" ID="cboPhong" DisplayField="TenPhong" ValueField="MaPhong"
                                                        Hidden="true" FieldLabel="Phòng" Disabled="true">
                                                        <Store>
                                                            <ext:Store runat="server" ID="storePhong" AutoLoad="true">
                                                                <Proxy>
                                                                    <ext:HttpProxy Url="/PhongKhoaHoc/GetByVien" />
                                                                </Proxy>
                                                                <Reader>
                                                                    <ext:JsonReader Root="data">
                                                                        <Fields>
                                                                            <ext:RecordField Name="ID" />
                                                                            <ext:RecordField Name="MaPhong" />
                                                                            <ext:RecordField Name="TenPhong" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                                <BaseParams>
                                                                    <ext:Parameter Name="MaVien" Value="#{cboVien}.value" Mode="Raw" />
                                                                </BaseParams>
                                                            </ext:Store>
                                                        </Store>
                                                        <Listeners>
                                                            <Select Fn="selectPhong" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                    <ext:ComboBox runat="server" ID="cboBan" Hidden="true" FieldLabel="Ban" DisplayField="TenBan"
                                                        ValueField="MaBan">
                                                        <Store>
                                                            <ext:Store runat="server" ID="storeBan" AutoLoad="true">
                                                                <Proxy>
                                                                    <ext:HttpProxy Url="/BanHanhChinh/GetAll" />
                                                                </Proxy>
                                                                <Reader>
                                                                    <ext:JsonReader Root="data">
                                                                        <Fields>
                                                                            <ext:RecordField Name="ID" />
                                                                            <ext:RecordField Name="MaBan" />
                                                                            <ext:RecordField Name="TenBan" />
                                                                        </Fields>
                                                                    </ext:JsonReader>
                                                                </Reader>
                                                            </ext:Store>
                                                        </Store>
                                                        <Listeners>
                                                            <Select Fn="selectBan" />
                                                        </Listeners>
                                                    </ext:ComboBox>
                                                    <ext:Hidden runat="server" ID="MaPhongBan" />
                                                    <ext:ComboBox runat="server" ID="ViTri" FieldLabel="Vị trí">
                                                        <Items>
                                                            <ext:ListItem Text="Trưởng" Value="TRUONG" />
                                                            <ext:ListItem Text="Phó" Value="PHO" />
                                                            <ext:ListItem Text="Nhân viên" Value="NHANVIEN" />
                                                        </Items>
                                                    </ext:ComboBox>
                                                </Items>
                                            </ext:Panel>
                                        </ext:LayoutColumn>
                                    </Columns>
                                </ext:ColumnLayout>
                            </Items>
                        </ext:FormPanel>
                    </div>
                    <div id="ja-colwrap">
                        <div class="ja-innerpad">
                            <div style="padding: 10px;">
                                <ext:CompositeField runat="server" ID="afterLogin" Hidden="true" LabelWidth="20">
                                    <Items>
                                        <ext:LinkButton runat="server" ID="UserID" />
                                        <ext:LinkButton ID="LinkButton1" runat="server" Text="(Đăng xuất)" NavigateUrl="/Account/Logout" />
                                    </Items>
                                </ext:CompositeField>
                                <ext:FormPanel runat="server" ID="frmLogin" Url="/Account/Login" Border="false" BodyBorder="false"
                                    Layout="FormLayout" AutoHeight="true" AutoWidth="true" LabelWidth="70">
                                    <Items>
                                        <ext:TextField runat="server" ID="Username" FieldLabel="Tài khoản" LabelWidth="50"
                                            AllowBlank="false" />
                                    </Items>
                                </ext:FormPanel>
                            </div>
                            <div style="padding-left: 155px;">
                                <ext:Button ID="btnLogin" runat="server" Text="Đăng nhập">
                                    <Listeners>
                                        <Click Fn="CommonFunction.submitLogin" />
                                    </Listeners>
                                </ext:Button>
                            </div>
                            <div id="Mod1" class="moduletable_menu">
                                <div class="ja-box-ct">
                                    <ul class="menu">
                                        <ext:MenuPanel runat="server" ID="MainMenu" Header="false" Border="false" />
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
